package com.teacherprofile.framework.aspectj;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class SecurityContextPropagationAspect {

    @Around("execution(* org.springframework.ai.tool..*.*(..))")
    public Object propagateSecurityContext(ProceedingJoinPoint joinPoint) throws Throwable {
        SecurityContext context = SecurityContextHolder.getContext();
        try {
            return joinPoint.proceed();
        } finally {
            SecurityContextHolder.setContext(context);
        }
    }
}